/*
 * config.h
 *
 *  Created on: Jan 14, 2014
 *      Author: ppks
 */

#ifndef CONFIG_H_
#define CONFIG_H_

/********************************************************************************/
/* Firmware Features Definition                                                 */
/********************************************************************************/
#define FW_FEATURE_UART_DEBUG           1

/********************************************************************************/
/* Board Specific Hardware Configuration                                        */
/********************************************************************************/
/* Board definitions */
#define BOARD_MULTI_WII_PRO             1
#define FC_BOARD_TYPE                   BOARD_MULTI_WII_PRO

/********************************************************************************/
/* Remote Control Configuration                                                 */
/********************************************************************************/
#define RC_TYPE_STANDARD_RX             1
#define REMOTE_CONTROL_RECEIVER_TYPE    RC_TYPE_STANDARD_RX

/*Internal i2c Pullups */
/* enable internal I2C pull ups (in most cases it is better to use external pullups) */
//#define INTERNAL_I2C_PULLUPS

/********************************************************************************/
/* Support multiple configuration profiles in EEPROM                            */
/********************************************************************************/
//#define MULTIPLE_CONFIGURATION_PROFILES

/********************************** Setup Section *******************************/
/********************************************************************************/
/* STEP 1: Select Multicopter Type                                              */
/********************************************************************************/
//#define MULTICOPTER_TYPE_QUAD_P
#define MULTICOPTER_TYPE_QUAD_X

/****************************    Motor minthrottle    *******************************/
/* Set the minimum throttle command sent to the ESC (Electronic Speed Controller)
   This is the minimum value that allow motors to run at a idle speed  */
//#define MINTHROTTLE 1300 // for Turnigy Plush ESCs 10A
//#define MINTHROTTLE 1120 // for Super Simple ESCs 10A
//#define MINTHROTTLE 1064 // special ESC (simonk)
//#define MINTHROTTLE 1050 // for brushed ESCs like ladybird
#define MINTHROTTLE             1150 // (*) (**)

/****************************    Motor maxthrottle    *******************************/
/* this is the maximum value for the ESCs at full power, this value can be increased up to 2000 */
#define MAXTHROTTLE             1850

/****************************    Mincommand          *******************************/
/* this is the value for the ESCs when they are not armed
   in some cases, this value must be lowered down to 900 for some specific ESCs, otherwise they failed to initiate */
#define MOTOR_MINCOMMAND        1000

#define RC_MINCHECK             1100
#define RC_MAXCHECK             1900
/* some radios have not a neutral point centered on 1500. can be changed here */
#define RC_MIDVALUE             1500

/********************************************************************************/
/* STEP 2: Select IMU componenets                                               */
/********************************************************************************/
/* Accelerometer */
#define MPU6050                 1
#define ACCELEROMETER_TYPE      MPU6050         /* Select type from defined list above, or 0 if disabled */

/* Gyroscope */
#define MPU6050                 1
#define GYROSCOPE_TYPE          MPU6050

/* Barometer */
#define MS561101BA              1
#define BAROMETER_TYPE          MS561101BA

/* Magnetometer */
#define HMC5883                 1
#define MAGNETOMETER_TYPE       HMC5883

/********************************************************************************/
/* Gyroscope Filters Configuration                                              */
/********************************************************************************/
/* MPU6050 Low pass filter setting. In case you cannot eliminate all vibrations to the Gyro, you can try
         to decrease the LPF frequency, only one step per try. As soon as twitching gone, stick with that setting.
         It will not help on feedback wobbles, so change only when copter is randomly twiching and all dampening and
         balancing options ran out. Uncomment only one option!
         IMPORTANT! Change low pass filter setting changes PID behaviour, so retune your PID's after changing LPF.*/

//#define MPU6050_LPF_256HZ     /* This is the default setting, no need to uncomment, just for reference */
//#define MPU6050_LPF_188HZ
//#define MPU6050_LPF_98HZ
//#define MPU6050_LPF_42HZ
//#define MPU6050_LPF_20HZ
//#define MPU6050_LPF_10HZ
//#define MPU6050_LPF_5HZ       /* Use this only in extreme cases, rather change motors and/or props */

/********************************************************************************/
/* Communication Interfaces Setup                                               */
/********************************************************************************/
 /* This is the speed of the serial interfaces */
#define SERIAL0_COM_SPEED       	115200
#define SERIAL1_COM_SPEED       	57600
#define SERIAL2_COM_SPEED       	115200
#define SERIAL3_COM_SPEED       	9600

/********************************************************************************/
/* GPS Configuration                                      				        */
/********************************************************************************/
//#define GPS_I2C_ENABLED
	#define GPS_I2C_ADDRESS			0x20

/* GPS using a SERIAL port
       if enabled, define here the Arduino Serial port number and the UART speed
       note: only the RX PIN is used in case of NMEA mode, the GPS is not configured by multiwii
       in NMEA mode the GPS must be configured to output GGA and RMC NMEA sentences (which is generally the default conf for most GPS devices)
       at least 5Hz update rate. uncomment the first line to select the GPS serial port of the arduino */
#define GPS_SERIAL_ENABLED
	#define GPS_SERIAL_PORT			2
	#define GPS_SERIAL_BAUDRATE		57600

/* GPS data readed from Misio-OSD - GPS module connected to OSD, and MultiWii read GPS data from OSD - tested and working OK ! */
//#define GPS_FROM_OSD_ENABLED

/* GPS protocol
       NMEA  - Standard NMEA protocol GGA, GSA and RMC  sentences are needed
       UBLOX - U-Blox binary protocol, use the ublox config file (u-blox-config.ublox.txt) from the source tree
       MTK_BINARY16 and MTK_BINARY19 - MTK3329 chipset based GPS with DIYDrones binary firmware (v1.6 or v1.9)
       With UBLOX and MTK_BINARY you don't have to use GPS_FILTERING in multiwii code !!! */
#define NMEA						0x01
#define UBLOX						0x02
#define MTK_BINARY16				0x03
#define MTK_BINARY19				0x04
#define INIT_MTK_GPS				0x05

#define GPS_PROTOCOL				UBLOX

#define GPS_NAVIGATION_ENABLED      1
//#define USE_MSP_WP                        	  /* Enables the MSP_WP command, which is used by WinGUI to display and log Home and Poshold positions */

//#define DONT_RESET_HOME_AT_ARM             	  /* HOME position is reset at every arm, uncomment it to prohibit it (you can set home position with GyroCalibration) */

/* indicate a valid GPS fix with at least 5 satellites by flashing the LED  - Modified by MIS - Using stable LED (YELLOW on CRIUS AIO) led work as sat number indicator
      - No GPS FIX -> LED blink at speed of incoming GPS frames
      - Fix and sat no. bellow 5 -> LED off
      - Fix and sat no. >= 5 -> LED blinks, one blink for 5 sat, two blinks for 6 sat, three for 7 ... */
#define GPS_LED_INDICATOR

/* GPS navigation can control the heading */
#define NAV_CONTROLS_HEADING       	1      	    /* copter faces toward the navigation point, maghold must be enabled for it */
#define NAV_TAIL_FIRST             	0     	    /* true - copter comes in with tail first  */
#define NAV_SET_TAKEOFF_HEADING    	1      	    /* true - when copter arrives to home position it rotates it's head to takeoff direction */

/* Get your magnetic declination from here : http://magnetic-declination.com/
   Convert the degree+minutes into decimal degree by ==> degree+minutes*(1/60)
   Note the sign on declination it could be negative or positive (WEST or EAST) */
#define MAG_DECLINATION            	16.2f		/* MAG Declination for Seattle, WA */

#define GPS_LEAD_FILTER                      	/* Adds a forward predictive filterig to compensate gps lag. Code based on Jason Short's lead filter implementation */

#define GPS_FILTERING                        	/* add a 5 element moving average filter to GPS coordinates, helps eliminate gps noise but adds latency comment out to disable */

#define GPS_WP_RADIUS              	100       	/* if we are within this distance to a waypoint then we consider it reached (distance is in cm) */
#define SAFE_WP_DISTANCE            500         /* Safe WP distance, do not start mission if the first wp distance is larger than this number (in meters)
                                                   Also aborts mission if the next waypoint distance is more than this number  */
#define NAV_SLEW_RATE              	30        	/* Adds a rate control to nav output, will smoothen out nav angle spikes */
#define MAX_NAV_ALTITUDE            100         /* Maximu allowable navigation altitude (in meters) automatic altitude control will not go above this height */
#define NAV_SPEED_MIN               100         /* minimum speed in [cm/s] when approach waypoint */
#define NAV_SPEED_MAX               400         /* maximum speed in [cm/s] to reach between waypoints */
#define NAV_SLOW_NAV                0           /* Slow down to zero when reaching waypoint (same as NAV_SPEED_MIN = 0) */
#define NAV_CROSSTRACK_GAIN         .4          /* Weight factor of the crosstrack error in navigation calculations (do not touch) */
#define NAV_BANK_MAX                3000        /* Maximum allowable banking than navigation outputs  */
#define NAV_RTH_ALTITUDE            15          /* Defines the RTH altitude. 0 means keep current alt during RTH (in meters) */
#define NAV_WAIT_FOR_RTH_ALT        1           /* Wait  to reach RTH alt before start moving to home (0-no, 1-yes) */
#define NAV_TAKEOVER_BARO           1           /* Navigation engine will takeover BARO mode control */
#define NAV_IGNORE_THROTTLE         1           /* Throttle stick input will be ignored  (only in BARO) */
#define NAV_FENCE_DISTANCE          600         /* If FENCE DISTANCE is larger than 0 then copter will switch to RTH when it farther from home
                                                 * than the defined number in meters */
#define LAND_SPEED                  100         /* This governs the descent speed during landing. 100 is equals approc 50cm/sec */

/* Temporarily Disables GPS_HOLD_MODE to be able to make it possible to adjust the Hold-position when moving the sticks.*/
#define GPS_AP_MODE                 40          /* Creates a deadspan for GPS. */

/* Check if the correct configuration is selected */
#if defined(GPS_I2C_ENABLED) && defined(GPS_SERIAL_ENABLED)
	#error "*** Please select only one GPS type either I2C or Serial ***"
#endif

/********************************************************************************/
/* RC Setup                                                                     */
/********************************************************************************/
/****************************    EXTENDED AUX STATES    *************************/
/* If you uncomment this line, you can use six states for each of the aux channels
 * (AUX1-AUX4) to control your copter.
 * Channel values
 * 1000-1230 : 1165
 * 1231-1360 : 1295
 * 1361-1490 : 1425
 * 1491-1620 : 1555
 * 1621-1749 : 1685
 * 1750-     : 1815

 * At this moment you can use this function only with WinGUI 2.3 release.
 * MultiWiiConf does not support it yet
 */

#define EXTENDED_AUX_STATES

/********************************************************************************/
/* Copter Type Specific Options                                                 */
/********************************************************************************/
/********************************  PID Controller *********************************/
/* choose one of the alternate PID control algorithms
 * 1 = evolved oldschool algorithm (similar to v2.2)
 * 2 = new experimental algorithm from Alex Khoroshko - unsupported - http://www.multiwii.com/forum/viewtopic.php?f=8&t=3671&start=10#p37387
 * */
#define PID_CONTROLLER      1

/* NEW: not used anymore for servo coptertypes  <== NEEDS FIXING - MOVE TO WIKI */
#define YAW_DIRECTION       1
//#define YAW_DIRECTION     -1 /* if you want to reverse the yaw correction direction */

#define ONLYARMWHENFLAT     /* prevent the copter from arming when the copter is tilted */

/********************************    ARM/DISARM    *********************************/
/* optionally disable stick combinations to arm/disarm the motors.
 * In most cases one of the two options to arm/disarm via TX stick is sufficient */
#define ALLOW_ARM_DISARM_VIA_TX_YAW
//#define ALLOW_ARM_DISARM_VIA_TX_ROLL

/********************************************************************************/
/* Altitude hold                                                                */
/********************************************************************************/

/* defines the neutral zone of throttle stick during altitude hold, default setting is
   +/-50 uncommend and change the value below if you want to change it. */
#define ALT_HOLD_THROTTLE_NEUTRAL_ZONE    50


/********************************************************************************/
/* motor, servo and other presets                                               */
/********************************************************************************/
 /* motors will not spin when the throttle command is in low position
    this is an alternative method to stop immediately the motors */
//#define MOTOR_STOP

/********************************************************************************/
/* Optional features                                                            */
/********************************************************************************/
/****************************  ngle throttle correction   ***********************/
/* Automatically increase throttle based on the angle of the copter
   Original idea by Kraut Rob, first implementation HAdrian */

//#define THROTTLE_ANGLE_CORRECTION 40

/********************************************************************************/
/* Mameory Saving                                                               */
/********************************************************************************/

/* options to counter the general shortage of both flash and ram memory */

/**** suppress handling of serial commands.***
 * This does _not_ affect handling of RXserial, Spektrum or GPS. Those will not be affected and still work the same.
 * Enable either one or both of the following options  */

/* Remove handling of all commands of the New MultiWii Serial Protocol.
* This will disable use of the GUI, winGUI, android apps and any other program that makes use of the MSP.
* You must find another way (like LCD_CONF) to tune the parameters or live with the defaults.
* If you run a LCD/OLED via i2c or serial/Bluetooth, this is safe to use */
//#define SUPPRESS_ALL_SERIAL_MSP

/* Remove handling of other serial commands.
* This includes navigating via serial the lcd.configuration menu, lcd.telemetry and permanent.log .
* Navigating via stick inputs on tx is not affected and will work the same.  */
//#define SUPPRESS_OTHER_SERIAL_COMMANDS

/**** suppress keeping the defaults for initial setup and reset in the code.
 * This requires a manual initial setup of the PIDs etc. or load and write from defaults.mwi;
 * reset in GUI will not work on PIDs
 */
//#define SUPPRESS_DEFAULTS_FROM_GUI

/********************************************************************************/
/* Failsafe Settings                                                            */
/********************************************************************************/
/* Failsafe check pulses on four main control channels CH1-CH4. If the pulse is missing or bellow 985us (on any of these four channels)
   the failsafe procedure is initiated. After FAILSAFE_DELAY time from failsafe detection, the level mode is on (if ACC or nunchuk is avaliable),
   PITCH, ROLL and YAW is centered and THROTTLE is set to FAILSAFE_THROTTLE value. You must set this value to descending about 1m/s or so
   for best results. This value is depended from your configuration, AUW and some other params.  Next, after FAILSAFE_OFF_DELAY the copter is disarmed,
   and motors are stopped. If RC pulse coming back before reached FAILSAFE_OFF_DELAY time, after the small quard time the RC control is returned to normal. */
#define FAILSAFE                                            /* uncomment  to activate the failsafe function */
#define FAILSAFE_DELAY              10                      /* Guard time for failsafe activation after signal lost. 1 step = 0.1sec - 1sec in example */
#define FAILSAFE_OFF_DELAY          200                     /* Time for Landing before motors stop in 0.1sec. 1 step = 0.1sec - 20sec in example */
#define FAILSAFE_THROTTLE           (MINTHROTTLE + 200)     /* (*) Throttle level used for landing - may be relative to MINTHROTTLE - as in this case */

#define FAILSAFE_RC_DETECT_TRESHOLD 985                     /* If the pulse on one of the motors is present but less than this value, the failsafe will be activated */

/********************************************************************************/
/* Battery Voltage Monitoring                                                   */
/********************************************************************************/
/* for V BAT monitoring
   after the resistor divisor we should get [0V;5V]->[0;1023] on analog V_BATPIN
   with R1=33k and R2=51k
   vbat = [0;1023]*16/VBATSCALE
   must be associated with #define BUZZER ! */

#define VBAT_ENABLED           	/* uncomment this line to activate the vbat code */
#define VBATSCALE       	117 /* (*) (**) change this value if readed Battery voltage is different than real voltage */
#define VBATNOMINAL     	126 /* 12,6V full battery nominal voltage - only used for lcd.telemetry */
#define VBATLEVEL_WARN1 	107 /* (*) (**) 10,7V */
#define VBATLEVEL_WARN2  	99 	/* (*) (**) 9.9V */
#define VBATLEVEL_CRIT   	93 	/* (*) (**) 9.3V - critical condition: if vbat ever goes below this value, permanent alarm is triggered */
#define NO_VBAT          	16 	/* Avoid beeping without any battery */
#define VBAT_SMOOTH 		16  /* length of averaging vector for smoothing the VBAT readings; should be power of 2; set to 1 to disable */

#endif /* CONFIG_H_ */
